package com.lm.akka.config;

import akka.actor.ActorSystem;
import akka.actor.Terminated;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.CompletionStage;

@Configuration
public class AkkaConfig {

    @Bean
    public ActorSystem actorSystem() {
        ActorSystem system = ActorSystem.create("spring-akka-system");
        // 优雅关闭钩子
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            CompletionStage<Terminated> terminate = (CompletionStage<Terminated>) system.terminate();
            terminate.toCompletableFuture().join();
        }));
        return system;
    }
}
